import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
import { App } from 'vue'
import Layout from '@/layout/index.vue'
import { error } from './error'

const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: 'main',
    component: Layout,
    redirect: '/test',
    meta: {
      title: '会议管理', icon: '会议管理'
    },
    children: [
      {
        path: 'test',
        name: 'test',
        component: () => import('@/views/helloView/index.vue'),
        meta: {
          title: '测试'
        }
      },
      {
        path: 'demo',
        name: 'demo',
        component: () => import('@/views/demoView/index.vue'),
        meta: {
          title: 'demo'
        }
      }
    ]
  },
  {
    path: '/hello',
    name: 'hello',
    component: Layout,
    redirect: '/hell/index',
    meta: {
      title: 'hell0', icon: '测试icon'
    },
    children: [
      {
        path: 'index',
        name: 'index',
        component: () => import('@/views/helloView/index.vue'),
        meta: {
          title: 'hello管理'
        }
      },
      {
        path: 'demo1',
        name: 'demo1',
        component: () => import('@/views/helloView/index.vue'),
        meta: {
          title: 'demo'
        }
      },
    ]
  },
  error
]

export const router = createRouter({
  routes,
  history: createWebHashHistory()
})

export const setupRouter = (app: App) => {
  app.use(router)
}
